package vn.aptech.scrumgroup.model;

import vn.aptech.scrumgroup.util.DrawUtil;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import demo.axitdn.physic.Unit;

public class ItemModel extends AbstractBaseModel {
	
	public float boardTop, boardLeft, cellSize;
	public int left, top;
	public ItemType type;
	private int topColor;
	
	public ItemModel(ItemType type){
		super(Color.parseColor("#fcfa98"), Color.parseColor("#7d71ae"));
		this.type = type;
		this.topColor = Color.parseColor("#f3f085");
		
		this.boardLeft = 0;
		this.boardTop = 0;
		this.cellSize = 0;
		this.left = 0;
		this.top = 0;
	}
	
	public ItemModel(ItemType type, int backColor, int foreColor, int topColor){
		super(backColor, foreColor);
		this.type = type;
		
		this.boardLeft = 0;
		this.boardTop = 0;
		this.cellSize = 0;
		this.left = 0;
		this.top = 0;
	}
	
	public ItemModel(float boardTop, float boardLeft, float cellSize, int left, int top, ItemType type, int backColor, int foreColor, int topColor){
		super(backColor, foreColor);
		this.topColor = topColor;
		this.boardLeft = boardLeft;
		this.boardTop = boardTop;
		this.cellSize = cellSize;
		this.left = left;
		this.top = top;
		this.type = type;
	}
	
	@Override
	public boolean isPointOf(float x, float y) {
		// TODO Auto-generated method stub
		if(y >= (boardTop + top * cellSize)  && y <= (boardTop + top * cellSize + cellSize) && x >= (boardLeft + left * cellSize) && x <= (boardLeft + left * cellSize + cellSize)){
			return true;
		}
		return false;
	}

	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint paint = new Paint();
		paint.setAntiAlias(true);
		
		//draw top of note
//		paint.setColor(Color.parseColor("#f3f085"));
		paint.setColor(topColor);
		c.drawRect(this.boardLeft + left * cellSize + 3*Unit.i, this.boardTop + top * cellSize + 1 * Unit.i, this.boardLeft + left * cellSize + cellSize - 2 * Unit.i, this.boardTop + top * cellSize + cellSize/5, paint);
		
		//draw note body
//		paint.setColor(Color.parseColor("#fcfa98"));
		paint.setColor(backColor);
		c.drawRect(this.boardLeft + left * cellSize + 3*Unit.i, this.boardTop + top * cellSize + cellSize / 5, this.boardLeft + left * cellSize + cellSize - 2 * Unit.i, this.boardTop + top * cellSize + cellSize - 2 * Unit.i, paint);
		
		//draw text
//		paint.setColor(Color.parseColor("#7d71ae"));
		paint.setColor(foreColor);
		float textSize = DrawUtil.calculateTextSize("Item", (this.boardLeft + left * cellSize + 4*Unit.i) - (this.boardLeft + left * cellSize + cellSize - 5 * Unit.i), paint, 3);
		paint.setTextSize(textSize - 2);
		String text="";
		if (type==ItemType.USER_STORY)
			text = "Story";
		else
			text = "Task";;
		c.drawText(text, this.boardLeft + left * cellSize + 4*Unit.i, this.boardTop + top * cellSize + cellSize / 5 + 2 * Unit.i - textSize, paint);
	}

	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub

	}

}
